import styles from './login.css'
import { Button, Input, message } from 'antd';
import React, { useState } from 'react';
import { UserOutlined, KeyOutlined } from '@ant-design/icons';
import axios from '../utils/index'
export default function (props) {
  const [username, updatename] = useState()
  const [password, updatepassword] = useState()

  const changename = (e) => {
    updatename(e.target.value)
  }
  const changepassword = (e) => {
    updatepassword(e.target.value)
  }
  const gologin = async () => {
    var res = await axios.post('login/', {
      username: username,
      password: password

    })
    console.log(res);
    if (res.status === 200) {
      message.success('登录成功')
      window.sessionStorage.setItem('token', res.data.data.token)
      props.history.push('/home')
    }
  }
  return (
    <div className={styles.normal}>
      <div >
        <div ></div>
        <div>
          <Input value={username} onChange={changename} prefix={<UserOutlined />} className={styles.inputt} />
        </div>
        <div>
          <Input.Password value={password} onChange={changepassword} prefix={<KeyOutlined />} className={styles.inputtt} />
        </div>
        <div className={styles.btn}>
          <Button type="primary" onClick={gologin} >登录</Button>
          <Button type="primary" className={styles.btnlaset}>重置</Button>
        </div>
      </div>
    </div>
  );
}

